package a_doubleWrite;

/**
 * todo
 *
 * @author luolidong
 * @version 1.0
 * @create 2021-07-29 10:56
 */
public class L168_1 {
    public static String test10To2(int num) {
        StringBuilder sb = new StringBuilder();
        while (num > 0) {
            sb.append(num % 2);
            num /= 2;
        }
        return sb.reverse().toString();
    }

    public static int test2To10(String binNum) {
        int len = binNum.length() - 1;
        int ans = 0;
        int i = 0;
        while (i <= len) {
            ans += Math.pow(2, len - i) * Integer.parseInt(binNum.charAt(i) + "");
            i++;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println("test(20) = " + test10To2(20));
        System.out.println("test2To10(test10To2(20)) = " + test2To10(test10To2(1)));
        System.out.println((char) (65 + 26));//A-65
        System.out.println((char) (65 + 32));//a-97
    }
}
